package com.master.train.business.controller;

import com.master.train.business.entity.DailyTrainEntity;
import com.master.train.business.service.DailyTrainService;
import com.master.train.common.utils.PageUtils;
import com.master.train.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;



/**
 * 每日车次
 *
 * @author master
 * @email 3221057417@qq.com
 * @date 2025-07-17 16:17:17
 */
@RestController
@RequestMapping("business/admin/daily-train")
public class DailyTrainController {
    @Autowired
    private DailyTrainService dailyTrainService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = dailyTrainService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		DailyTrainEntity dailyTrain = dailyTrainService.getById(id);

        return R.ok().put("dailyTrain", dailyTrain);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DailyTrainEntity dailyTrain){
        Date now = new Date();
        if (dailyTrain.getId() == null){
            dailyTrain.setCreateTime(now);
            dailyTrain.setUpdateTime(now);
        }else {
            dailyTrain.setUpdateTime(now);
        }
		dailyTrainService.saveOrUpdate(dailyTrain);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody DailyTrainEntity dailyTrain){
		dailyTrainService.updateById(dailyTrain);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		dailyTrainService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
